package cn.gson.crm.model.pojo;

import java.io.Serializable;
import javax.persistence.*;

import com.alibaba.fastjson.annotation.JSONField;

import java.util.List;


/**
 * The persistent class for the "ROLE" database table.
 * 
 */
@Entity
@Table(name="ROLE")
@NamedQuery(name="Role.findAll", query="SELECT r FROM Role r")
public class Role implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(name="ROLE_RID_GENERATOR",sequenceName="SEQ_ROLE")
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="ROLE_RID_GENERATOR")
	@Column(name="R_ID")
	private long rId;

	@Column(name="R_DESCRIBE")
	private String rDescribe;

	@Column(name="R_NAME")
	private String rName;

	//bi-directional many-to-one association to EmpsRole
	@OneToMany(mappedBy="role")
	@JSONField(serialize=false)
	private List<EmpsRole> empsRoles;

	//bi-directional many-to-many association to Function
	@ManyToMany
	@JoinTable(
		name="ROLES_FUNCTIONS"
		, joinColumns={
			@JoinColumn(name="R_ID")
			}
		, inverseJoinColumns={
			@JoinColumn(name="F_ID")
			}
		)
	@JSONField(serialize=false)
	private List<Function> functions;

	public Role() {
	}

	public long getRId() {
		return this.rId;
	}

	public void setRId(long rId) {
		this.rId = rId;
	}

	public String getRDescribe() {
		return this.rDescribe;
	}

	public void setRDescribe(String rDescribe) {
		this.rDescribe = rDescribe;
	}

	public String getRName() {
		return this.rName;
	}

	public void setRName(String rName) {
		this.rName = rName;
	}

	public List<EmpsRole> getEmpsRoles() {
		return this.empsRoles;
	}

	public void setEmpsRoles(List<EmpsRole> empsRoles) {
		this.empsRoles = empsRoles;
	}

	public EmpsRole addEmpsRole(EmpsRole empsRole) {
		getEmpsRoles().add(empsRole);
		empsRole.setRole(this);

		return empsRole;
	}

	public EmpsRole removeEmpsRole(EmpsRole empsRole) {
		getEmpsRoles().remove(empsRole);
		empsRole.setRole(null);

		return empsRole;
	}

	public Role(long rId, String rDescribe, String rName) {
		super();
		this.rId = rId;
		this.rDescribe = rDescribe;
		this.rName = rName;
	}

	public List<Function> getFunctions() {
		return this.functions;
	}

	public void setFunctions(List<Function> functions) {
		this.functions = functions;
	}

}